home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / Pascal Demos / Skel / Skel.p next >
Text File  |  1996-01-25  |  4KB  |  182 lines

  1. program Skel;
  2.  
  3.     uses
  4.         Types, Memory, QuickDraw, Windows, Dialogs, Menus, TextUtils, ToolUtils, TransSkel;
  5.  
  6.     const
  7.         fileMenuRes = 129;        { File menu }
  8.         aboutAlrtRes = 1000;    { About box }
  9.         theWindRes = 260;        { Window }
  10.         reportDlog = 257;        { message dialog box }
  11.         aboutStr = 128;            { message strings }
  12.         rattleStr = 129;
  13.         frightStr = 130;
  14.  
  15.         { dialog item numbers }
  16.  
  17.         okayItem = 1;
  18.         messageItem = 2;
  19.         titleItem = 3;
  20.         outlineItem = 4;
  21.  
  22.         { File menu item numbers }
  23.  
  24.         rattle = 1;
  25.         frighten = 2;
  26.         { gray line }
  27.         quit = 4;
  28.  
  29.     var
  30.  
  31.         theWind: WindowPtr;
  32.         fileMenu: MenuHandle;
  33.  
  34.  
  35.     { Read a string resource and put into the Alert/Dialog paramtext values }
  36.  
  37.     procedure SetParamText (strNum: Integer);
  38.         var
  39.             h: StringHandle;
  40.             flags: SignedByte;
  41.     begin
  42.         h := GetString(strNum);
  43.         flags := HGetState(Handle(h));
  44.         HLock(Handle(h));
  45.         ParamText(h^^, '', '', '');
  46.         HSetState(Handle(h), flags);
  47.     end;
  48.  
  49.  
  50.     { Put up a dialog box with a message and an OK button.  The message }
  51.     { is stored in the 'STR ' resource whose number is passed as strNum. }
  52.  
  53.     procedure Report (strNum: Integer);
  54.         var
  55.             theDialog: DialogPtr;
  56.             savePort: GrafPtr;
  57.             itemHit: Integer;
  58.     begin
  59.         SetParamText(strNum);
  60.         theDialog := GetNewDialog(reportDlog, nil, WindowPtr(-1));
  61.         SkelPositionWindow(theDialog, skelPositionOnParentDevice, FixRatio(1, 2), FixRatio(1, 5));
  62.  
  63.         GetPort(savePort);
  64.         SetPort(theDialog);
  65.         SkelSetDlogButtonOutliner(theDialog, outlineItem);
  66.         ShowWindow(theDialog);
  67.         ModalDialog(SkelDlogFilter(nil, true), itemHit);
  68.         SkelRmveDlogFilter;
  69.         DisposeDialog(theDialog);
  70.         SetPort(savePort);
  71.     end;
  72.  
  73.  
  74.     { Handle selection of "About Skel..." item from Apple menu }
  75.  
  76.     procedure DoAppleMenu (item: Integer);
  77.         var
  78.             ignore: Integer;
  79.     begin
  80.         SetParamText(aboutStr);
  81.         ignore := SkelAlert(aboutAlrtRes, SkelDlogFilter(nil, true), skelPositionOnParentDevice);
  82.         SkelRmveDlogFilter;
  83.     end;
  84.  
  85.  
  86.     { Process selection from File menu. }
  87.     { Rattle, Frighten    A dialog box with message }
  88.     { Quit                Request a halt by calling SkelStopEventLoop().  This }
  89.     {                    makes SkelMain return. }
  90.  
  91.     procedure DoFileMenu (item: Integer);
  92.     begin
  93.         case item of
  94.             rattle: 
  95.                 Report(rattleStr);
  96.             frighten: 
  97.                 Report(frightStr);
  98.             quit: 
  99.                 SkelStopEventLoop;    { request halt }
  100.         end;
  101.     end;
  102.  
  103.  
  104.     { Initialize menus . Tell TransSkel to process the Apple menu }
  105.     { automatically, and associate the proper procedures with the }
  106.     { File and Edit menus . }
  107.     { \311 is the ellipsis character. }
  108.  
  109.     procedure SetupMenus;
  110.         var
  111.             ignore: Boolean;
  112.     begin
  113.         SkelApple('About Skel…', @DoAppleMenu);
  114.         fileMenu := GetMenu(fileMenuRes);
  115.         ignore := SkelMenu(fileMenu, @DoFileMenu, nil, false, true);
  116.     end;
  117.  
  118.  
  119. { Window Handling Routines }
  120.  
  121. { On update event, can ignore the resizing information, since the whole }
  122. { window is always redrawn in terms of the current size, anyway. }
  123. { Content area is dark gray except scroll bar areas, which are white. }
  124. { Draw grow box as well. }
  125.  
  126. { Note that we can assume the current port is set to theWind. }
  127.  
  128.     procedure Update (resized: Boolean);
  129.         var
  130.             r: Rect;
  131.     begin
  132.         r := theWind^.portRect;            { paint window dark gray }
  133.         r.bottom := r.bottom - 15;        { don't bother painting the }
  134.         r.right := r.right - 15;            { scroll bar areas }
  135.         FillRect(r, qd.dkGray);
  136.         r := theWind^.portRect;            { paint scroll bar areas white }
  137.         r.left := r.right - 15;
  138.         FillRect(r,qd. white);
  139.         r := theWind^.portRect;
  140.         r.top := r.bottom - 15;
  141.         FillRect(r,qd. white);
  142.         DrawGrowIcon(theWind);
  143.     end;
  144.  
  145.  
  146.     procedure Activate (active: Boolean);
  147.     begin
  148.         DrawGrowIcon(theWind);        { make grow box reflect new window state }
  149.     end;
  150.  
  151.  
  152.     procedure Clobber;
  153.     begin
  154.         DisposeWindow(theWind);
  155.     end;
  156.  
  157.  
  158. { Read window from resource file and install handler for it.  Mouse }
  159. { and key clicks are ignored.  There is no close proc since the window }
  160. { doesn't have a close box.  There is no idle proc since nothing is }
  161. { done while the window is in front (all the things that are done are }
  162. { handled by TransSkel). }
  163.  
  164.     procedure WindInit;
  165.         var
  166.             ignore: Boolean;
  167.     begin
  168.         if (SkelQuery(skelQHasColorQD) <> 0) then
  169.             theWind := GetNewCWindow(theWindRes, nil, WindowPtr(-1))
  170.         else
  171.             theWind := GetNewWindow(theWindRes, nil, WindowPtr(-1));
  172.         ignore := SkelWindow(theWind, nil, nil, @Update, @Activate, nil, @Clobber, nil, false);
  173.     end;
  174.  
  175.  
  176. begin
  177.     SkelInit(nil);
  178.     SetupMenus;
  179.     WindInit;
  180.     SkelEventLoop;
  181.     SkelCleanup;
  182. end.